//
//  GWUser.m
//  ShandsMod
//
//  Created by zh_s on 2019/9/27.
//  Copyright © 2019 zh_s. All rights reserved.
//

#import "GWUser.h"

@implementation GWUser

+ (void)writeIsLogin:(BOOL)pIsLogin
{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:[NSNumber numberWithInteger:pIsLogin] forKey:@"isLogin"];
    [userDefault synchronize];
}
+ (BOOL)readIsLogin
{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    return [[userDefault objectForKey:@"isLogin"] boolValue];
}

+ (void)writeObject:(GWUserDefaultsObj *)pObject
{
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:pObject];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:data forKey: [[pObject class] description] ];
    [user synchronize];
}

+ (void)writeIsPresentView:(BOOL)isPresentView {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:[NSNumber numberWithInteger:isPresentView] forKey:@"isPresentView"];
    [userDefault synchronize];
}
+ (BOOL)readIsPresentView {
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    return [[userDefault objectForKey:@"isPresentView"] boolValue];
}


+ (void)writeIsGuestMode:(BOOL)isGuestMode{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:[NSNumber numberWithInteger:isGuestMode] forKey:@"isGuestMode"];
    [userDefault synchronize];
}
+ (BOOL)readIsGuestMode{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    return [[userDefault objectForKey:@"isGuestMode"] boolValue];
}

+ (void)writeIsReal:(BOOL)pIsReal{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    [userDefault setObject:[NSNumber numberWithInteger:pIsReal] forKey:@"isReal"];
    [userDefault synchronize];
}
+ (BOOL)readIsReal{
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    return [[userDefault objectForKey:@"isReal"] boolValue];
}

+ (GWUserDefaultsObj *)readObject:(NSString *)pObjectName
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSData *data = [user objectForKey: pObjectName ];
    return nil==data?nil:[NSKeyedUnarchiver unarchiveObjectWithData:data];
}

+ (GWUserData *)readUser
{
    return (GWUserData *)[GWUser readObject:@"GWUserData"];
}



@end
